<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="154px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="地面照射风化参数组" prop="CHNGWTRM001">
									<select-para
										style="width:100%"
										size="medium"
										class="mediumForm"
										v-model="ruleForm.CHNGWTRM001"
										:label.sync="ruleForm.CHNGWTRM001"
										:options="CHNGWTRM001options"
										@change="CHNGWTRMnumChange()"
									></select-para>
								</el-form-item>

								<el-table ref="form" :data="ruleForm.allCHNGWTRM" tooltip-effect="dark" border width="70%">
									<el-table-column prop="CHGWCOEF001" label="风化系数" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHGWCOEF001"
												:prop="'allCHNGWTRM.'+scope.$index+'.CHGWCOEF001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHGWCOEF001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column prop="CHTGWHLF001" label="风化半衰期" min-width="120" align="center">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHTGWHLF001"
												:prop="'allCHNGWTRM.'+scope.$index+'.CHTGWHLF001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHTGWHLF001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
								</el-table>
							</el-col>
						</el-row>
						<div class="separate"></div>
						<el-row>
							<el-col :span="24">
								<el-form-item label="再悬浮风化参数组" prop="CHNRWTRM001">
									<select-para
										style="width:100%"
										size="medium"
										class="mediumForm"
										v-model="ruleForm.CHNRWTRM001"
										:label.sync="ruleForm.CHNRWTRM001"
										:options="CHNRWTRM001options"
										@change="CHNRWTRMnumChange()"
									></select-para>
								</el-form-item>

								<el-table ref="multipleTable" :data="ruleForm.allCHNRWTRM" tooltip-effect="dark" border>
									<el-table-column prop="CHRWCOEF001" label="风化系数" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHRWCOEF001"
												:prop="'allCHNRWTRM.'+scope.$index+'.CHRWCOEF001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHRWCOEF001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column prop="CHTRWHLF001" label="风化半衰期" min-width="120" align="center">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHTRWHLF001"
												:prop="'allCHNRWTRM.'+scope.$index+'.CHTRWHLF001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHTRWHLF001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
								</el-table>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
import { dome, selecttext } from "@/utils/verify.js"
// import {
//     saveslbaseinfo,
//     slbaseinfo
// } from '../service.js';
export default {
	name: "aboutUs",
	props: {},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},

	data() {
		//表格
		var C10E2010 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-20 || value > 1.0) {
				callback(new Error("输入范围为[1.0E-20，1.0]"))
			} else {
				callback()
			}
		}

		var C10E610E12 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-6 || value > 1.0e12) {
				callback(new Error("输入范围为[1.0E-6,1.0E+12]"))
			} else {
				callback()
			}
		}

		return {
			activeTab: "4",

			ruleForm: {
				CHNGWTRM001: "1",
				CHNRWTRM001: "1",
				allCHNGWTRM: [
					{
						CHGWCOEF001: "",
						CHTGWHLF001: "",
					},
				],
				allCHNRWTRM: [
					{
						CHRWCOEF001: "",
						CHTRWHLF001: "",
					},
				],
			},
			rules: {
				CHNGWTRM001: [
					{
						validator: selecttext,
						trigger: ["change", "blur"],
					},
				],
				CHGWCOEF001: [
					{
						validator: C10E2010,
						trigger: ["change", "blur"],
					},
				],
				CHTGWHLF001: [
					{
						validator: C10E610E12,
						trigger: ["change", "blur"],
					},
				],
				CHNRWTRM001: [
					{
						validator: selecttext,
						trigger: ["change", "blur"],
					},
				],
				CHRWCOEF001: [
					{
						validator: C10E2010,
						trigger: ["change", "blur"],
					},
				],
				CHTRWHLF001: [
					{
						validator: C10E610E12,
						trigger: ["change", "blur"],
					},
				],
			},
			CHNGWTRM001options: [
				{
					label: "1",
					value: "1",
				},
				{
					label: "2",
					value: "2",
				},
			],
			CHNRWTRM001options: [
				{
					label: "1",
					value: "1",
				},
				{
					label: "2",
					value: "2",
				},
				{
					label: "3",
					value: "3",
				},
			],

			loading: false,
		}
	},
	computed: {
		...mapState({
			basic_Data: (state) => state.token.basic_Data,
			early_Data: (state) => state.token.early_Data,
			longterm_Data: (state) => state.token.longterm_Data,
		}),
	},
	mounted() {
		this.setData()
	},
	methods: {
		setData() {
			this.ruleForm.CHNGWTRM001 = this.longterm_Data.CHNGWTRM001
				? this.longterm_Data.CHNGWTRM001.toString()
				: "1"
			this.ruleForm.CHNRWTRM001 = this.longterm_Data.CHNRWTRM001
				? this.longterm_Data.CHNRWTRM001.toString()
				: "1"
			this.ruleForm.allCHNRWTRM = []
			for (let index = 0; index < this.ruleForm.CHNRWTRM001; index++) { 
				let tempitem = {
					CHRWCOEF001: this.longterm_Data.CHRWCOEF001[index]
						? this.longterm_Data.CHRWCOEF001[index].toString()
						: "1",
					CHTRWHLF001: this.longterm_Data.CHTRWHLF001[index]
						? this.longterm_Data.CHTRWHLF001[index].toString()
						: "1",
				} 
				this.ruleForm.allCHNRWTRM.push(tempitem)
			} 
		},

		CHNGWTRMnumChange() {
			if (this.ruleForm.CHNGWTRM001) {
				this.ruleForm.allCHNGWTRM = []
				for (
					let index = 0;
					index < this.ruleForm.CHNGWTRM001;
					index++
				) { 
					let tempitem = {
						CHGWCOEF001: this.longterm_Data.CHGWCOEF001[index]
							? this.longterm_Data.CHGWCOEF001[index].toString()
							: "1",
						CHTGWHLF001: this.longterm_Data.CHTGWHLF001[index]
							? this.longterm_Data.CHTGWHLF001[index].toString()
							: "1",
					} 
					this.ruleForm.allCHNGWTRM.push(tempitem)
				} 
			}
		},
		CHNRWTRMnumChange() { 
			if (this.ruleForm.CHNRWTRM001) {
				this.ruleForm.allCHNRWTRM = []
				for (
					let index = 0;
					index < this.ruleForm.CHNRWTRM001;
					index++
				) { 
					let tempitem = {
						CHRWCOEF001: this.longterm_Data.CHRWCOEF001[index]
							? this.longterm_Data.CHRWCOEF001[index].toString()
							: "1",
						CHTRWHLF001: this.longterm_Data.CHTRWHLF001[index]
							? this.longterm_Data.CHTRWHLF001[index].toString()
							: "1",
					} 
					this.ruleForm.allCHNRWTRM.push(tempitem)
				} 
			}
		},
		submitFun() {
			//保存
			this.$refs.form.validate((valid) => {
				if (valid) { 
					let tempdata = JSON.parse(
						JSON.stringify(this.longterm_Data)
					) 
					tempdata.CHNGWTRM001 = parseInt(this.ruleForm.CHNGWTRM001) 
					tempdata.CHGWCOEF001 = this.ruleForm.allCHNGWTRM.map(
						(item) => {
							return parseFloat(item.CHGWCOEF001)
						}
					)
					tempdata.CHTGWHLF001 = this.ruleForm.allCHNGWTRM.map(
						(item) => {
							return parseFloat(item.CHTGWHLF001)
						}
					)
					tempdata.CHNRWTRM001 = parseInt(this.ruleForm.CHNRWTRM001)
					tempdata.CHRWCOEF001 = this.ruleForm.allCHNRWTRM.map(
						(item) => {
							return parseFloat(item.CHRWCOEF001)
						}
					)
					tempdata.CHTRWHLF001 = this.ruleForm.allCHNRWTRM.map(
						(item) => {
							return parseFloat(item.CHTRWHLF001)
						}
					) 
					tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_longterm_Data", tempdata)
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "CHANGQI",
						submitjson: JSON.stringify(tempdata),
					} 
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => { 
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "保存失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "保存成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_longterm_showTab",
						this.activeTab
					)
				}
			})
		},
		daochu() {
			//导出
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>